/*
 * Created on Nov 27, 2005
 */
package dbsucxentW.pathProcessorEdgeW;

import dbsucxentW.constantW.EdgeConstant;

/**
 * @author Seah Boon Siew
 * modified by Klarinda 20070525: use sucxent++'s step (copy & paste sucxent++'s Step class)
 */
public class Step {
	String _axis, _nameTest; 
	String[] _predicate, _equality, _equalityOperator;
	boolean _hasPredicate; 
	boolean[] _hasEquality;
	int typeId; 
	int[] _toPred, _fromPred;
	//klarinda 20061122
    int[] 		_noOfOpenParenthesis; 
    int[] 		_noOfCloseParenthesis;
    boolean[] 	_andExpr; 			
    boolean[] 	_orExpr;				
    //end of klarinda
    
/*	public static int CHILD = 0, FOLLOWING = 1, PRECEDING = 2, FOLLOWING_SIBLING = 3, PRECEDING_SIBLING = 4;
	public static int ATTRIBUTE = 5, PARENT = 6, SELF = 7;
	public static int ANCESTOR = 8, ANCESTOR_OR_SELF = 9, DESCENDANT = 10, DESCENDANT_OR_SELF = 11;
*/	
	
	public Step(String axis, String nameTest, String[] predicate, String[] equality, boolean hasPredicate, boolean[] hasEquality, String[] equalityOperator,
			int[] openPar, int[] closePar, boolean[] and, boolean or[]){	//added by klarinda 20061122
		
		_axis = axis;
		_nameTest = nameTest;
		_predicate = predicate;
		_equality = equality;
		_hasPredicate = hasPredicate;
		_hasEquality = hasEquality;
		_equalityOperator = equalityOperator;

		//klarinda 20061122
	    _noOfOpenParenthesis = openPar; 
	    _noOfCloseParenthesis = closePar;
	    _andExpr = and; 			
	    _orExpr = or;				
		//end of klarinda
	    
		if (axis.compareTo("child") == 0){
			typeId = EdgeConstant.CHILD;
		} else if (axis.compareTo("following") == 0){
			typeId = EdgeConstant.FOLLOWING;
		} else if (axis.compareTo("preceding") == 0){
			typeId = EdgeConstant.PRECEDING;
		} else if (axis.compareTo("following-sibling") == 0){
			typeId = EdgeConstant.FOLLOWING_SIBLING;
		} else if (axis.compareTo("preceding-sibling") == 0){
			typeId = EdgeConstant.PRECEDING_SIBLING;
		} else if (axis.compareTo("attribute") == 0){
			//klarinda 20061108 typeId = EdgeConstant.CHILD;
			//klarinda 20061108 _nameTest = "@" + _nameTest;
			typeId = EdgeConstant.ATTRIBUTE;		//klarinda 20061108 
		} else if (axis.compareTo("parent") == 0){
			typeId = EdgeConstant.PARENT;
		} else if (axis.compareTo("self") == 0){
			typeId = EdgeConstant.SELF;
		} else if (axis.compareTo("ancestor") == 0){
			typeId = EdgeConstant.ANCESTOR;
		} else if (axis.compareTo("ancestor-or-self") == 0){
			typeId = EdgeConstant.ANCESTOR_OR_SELF;
		} else if (axis.compareTo("descendant") == 0){
			typeId = EdgeConstant.DESCENDANT;
		} else if (axis.compareTo("descendant-or-self") == 0){
			typeId = EdgeConstant.DESCENDANT_OR_SELF;
		}
		
		_fromPred = new int[predicate.length];
		_toPred = new int[predicate.length];
		
		
		// split TO, if any
		for (int i = 0; i < predicate.length; i++)
		if (_hasEquality[i] == false && _hasPredicate == true){
			
			_predicate[i] = _predicate[i].toUpperCase();
			
			String[] toParts = _predicate[i].split("TO");
				if (toParts.length > 1){
					Integer castedInt = new Integer(toParts[0].trim());
					_fromPred[i] = castedInt.intValue();					
					castedInt = new Integer(toParts[1].trim());
					_toPred[i] = castedInt.intValue();
				}else{
					Integer castedInt = new Integer(toParts[0].trim());
					_fromPred[i] = castedInt.intValue();
					_toPred[i] = _fromPred[i];
				}
			 
		}
	}
	
	public String[] getEqualityOperator() {
		return _equalityOperator;
	}

	public String getEqualityOperator(int i) {
		return _equalityOperator[i];
	}

	public String getAxis(){
		return _axis;
	}
	
	public String getNameTest(){
		return _nameTest;
	}
	
	public String[] getPredicate(){
		return _predicate;
	}

	public String getPredicate(int i){
		return _predicate[i];
	}
	
	public String[] getEquality(){
		return _equality;
	}

	public String getEquality(int i){
		return _equality[i];
	}

	public int[] getPredicateFrom(){
		return _fromPred;
	}
	
	public int getPredicateFrom(int i){
		return _fromPred[i];
	}
	
	public int[] getPredicateTo(){		
		return _toPred;
	}
	
	public int getPredicateTo(int i){		
		return _toPred[i];
	}
	
	public int getType(){
		return typeId;
	}
	
	public boolean hasPredicate(){
		return _hasPredicate;
	}
	
	public boolean[] hasEquality(){
		return _hasEquality;
	}

	public boolean hasEquality(int i){
		return _hasEquality[i];
	}
	
	public int getPredicateType(){
		int typ = -1;
		
		//klarinda 20060811, add node() if (_nameTest.compareTo("*") == 0){
		if (_nameTest.compareTo("*") == 0 || _nameTest.compareTo("node()") == 0){//klarinda 20060811
			typ = 0;
		} else {
			typ = 1;
		}
		
		return typ;
	}

	//the following functions added by klarinda 20061122
	public boolean[] getAndExpr() {
		return _andExpr;
	}
	public boolean getAndExpr(int i) {
		return _andExpr[i];
	}

	public boolean[] getOrExpr() {
		return _orExpr;
	}
	public boolean getOrExpr(int i) {
		return _orExpr[i];
	}

	public int[] getNoOfCloseParenthesis() {
		return _noOfCloseParenthesis;
	}
	public int getNoOfCloseParenthesis(int i) {
		return _noOfCloseParenthesis[i];
	}

	public int[] getNoOfOpenParenthesis() {
		return _noOfOpenParenthesis;
	}
	public int getNoOfOpenParenthesis(int i) {
		return _noOfOpenParenthesis[i];
	}

	
}
